$(function(){
    var float = false;
    $(".btn-goNext").on('click',function() {
        $('html, body').animate({scrollTop: $(document).height()}, 300);
    });

    // 手机号正确按钮可点击
    $("#phone").on('input',function(){
        var str = document.getElementById("phone").value
        var myreg=/^[1][3,4,5,6,7,8][0-9]{9}$/;
        if (myreg.test(str)) {
            $("#btn-sure").removeAttr('disabled').css({'background': '-webkit-linear-gradient(left, #4595fa , #1e73e0)','background': '-o-linear-gradient(right, #4595fa, #1e73e0)','background': '-moz-linear-gradient(right, #4595fa, #1e73e0)','background': 'linear-gradient(to right, #4595fa , #1e73e0)'});
        } else {
            $("#btn-sure").attr('disabled','disabled').css('background','#9d9d9d');
            return false;
        }
    });
    $("#phone").focus(function(event) {
        if($(this).attr('placeholder') == '请输入手机号'){
            $(this).val('');
            $(this).attr('placeholder','');
        }
    });
    $("#phone").blur(function(event) {
        if($(this).val() ==''){
            $(this).val('请输入手机号');
            $(this).attr('placeholder','请输入手机号');
        }

    });

    // 弹窗
    $("#btn-sure").on('click',function() {
        var phone = $('#phone').val();

        if(float == false) {
            float = true;
            layer.msg('预约中', {
                icon: 16
                ,shade: 0.01
            });
            $.ajax({
                url: '/index.php/mobile/index',
                data: {phone: phone},
                type: 'post',
                dataType: 'json',
                success: function (json) {
                    layer.closeAll();
                    if(json.code ==1){
                        $('.pop-box').fadeIn('fast');
                    }else{
                        layer.msg(json.msg, {icon: 4});
                    }
                }
            })
        }
    });
    $("#closeBtn").on('click',function() {
        $('.pop-box').fadeOut('fast');
        $(".btm-box").html('<p style="color:#1266d1;text-align: center;font-size: 0.4rem;font-weight: bold;">您已预约成功！</p>')
    });
});